/********************************************
 * 功能说明:
 * 模块名称:
 * 系统名称:
 * 软件版权: Frank
 * 系统版本: 1.0.0
 * 开发人员: Frank
 * 开发时间: 2019/12/12 22:47
 * 审核人员:
 * 相关文档:
 * 修改记录: 修改日期 修改人员 修改说明
 *********************************************/
package com.spring.arch.uaa.setup;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.spring.arch.common.enums.DataType;
import com.spring.arch.common.enums.Gender;
import com.spring.arch.common.setup.IApplicationSetup;
import com.spring.arch.common.setup.SetupOrder;
import com.spring.arch.uaa.enums.*;
import com.spring.arch.common.enums.DataType;
import com.spring.arch.common.enums.Gender;
import com.spring.arch.common.setup.IApplicationSetup;
import com.spring.arch.common.setup.SetupOrder;
import com.spring.arch.uaa.enums.*;
import com.spring.arch.uaa.model.*;
import com.spring.arch.uaa.repository.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static com.spring.arch.uaa.enums.Constant.GLOBAL_DEFAULT_PASSWORD;

/**
 * 应用初始化程序
 *
 * @author Frank
 * @version 1.0.0.1
 * @since 2019/12/12 22:47
 */
@Slf4j
@Component
@SetupOrder(1)
public class UaaSetup implements IApplicationSetup {


    private static final String DEFAULT_PASSWORD_SALT = "SXJKFD";
    private static final String[] grantTypes = {"password", "refresh_token"};
    private static final String[] resourceIds = {"uaa", "estate", "brc", "fundamental", "exhibition", "operation", "iot", "file", "bpm", "collectivization", "all"};

    private User superAdminUser;
    private User zhongLiangAdminUser;

    private Role superAdminRole;
    private Role tenantAdminRole;
    private Role projectAdminRole;

    private Tenant internalTenant;
    private TenantEmployee internalTenantEmployee;
    private Organization internalTenantRootOrg;


    @Autowired
    private OauthClientRepository oauthClientRepository;
    @Autowired
    private PasswordEncoder passwordEncoder;
    @Autowired
    private AuthorityRepository authorityRepository;
    @Autowired
    private RoleRepository roleRepository;
    @Autowired
    private RoleAuthorityRepository roleAuthorityRepository;
    @Autowired
    private UserRepository userRepository;
    @Autowired
    private TenantRepository tenantRepository;
    @Autowired
    private OrganizationRepository organizationRepository;
    @Autowired
    private TenantEmployeeRepository tenantEmployeeRepository;
    @Autowired
    private OrganizationEmployeeRepository organizationEmployeeRepository;
    @Autowired
    private OrganizationEmployeeRoleRepository organizationEmployeeRoleRepository;

    @Override
    public boolean initDBData(String... args) {
        // 初始化Oauth2客户端
        initOauth2Client();
        // 初始化角色信息
        initRoleData();
        // 初始化权限信息
        initAuthorities();
        // 初始化超级管理员
        initSuperAdmin();
        // 初始化默认租户
        initInternalTenant();
        // 初始化中粮admin
        initTenantAdminForZhongliang();
        // 初始化中粮物业
        initZhongLiangTenant();
        return true;
    }

    private void initOauth2Client() {
        Optional<OauthClient> oauthClient = oauthClientRepository.findById(Constant.OAUTH_CLIENT_ID_WEB);
        if (!oauthClient.isPresent()) {
            OauthClient webClient = new OauthClient()
                    .setClientId(Constant.OAUTH_CLIENT_ID_WEB)
                    .setClientSecret(passwordEncoder.encode(Constant.GLOBAL_DEFAULT_PASSWORD))
                    .setResourceIds(Sets.newHashSet(resourceIds))
                    .setAuthorizedGrantTypes(Sets.newHashSet(grantTypes[0], grantTypes[1]))
                    .setScope(Sets.newHashSet((Constant.OAUTH_CLIENT_ID_WEB)))
                    .setSecretRequired(true)
                    .setAccessTokenValiditySeconds(7 * 24 * 3600 * 1000)
                    .setRefreshTokenValiditySeconds(7 * 24 * 3600 * 1000)
                    .setScoped(false);
            oauthClientRepository.save(webClient);

            OauthClient mobileClient = new OauthClient()
                    .setClientId(Constant.OAUTH_CLIENT_ID_MOBILE)
                    .setClientSecret(passwordEncoder.encode(Constant.GLOBAL_DEFAULT_PASSWORD))
                    .setResourceIds(Sets.newHashSet(resourceIds))
                    .setAuthorizedGrantTypes(Sets.newHashSet(grantTypes[0], grantTypes[1]))
                    .setScope(Sets.newHashSet(Constant.OAUTH_CLIENT_ID_MOBILE))
                    .setSecretRequired(true)
                    .setAccessTokenValiditySeconds(7 * 24 * 3600 * 1000)
                    .setRefreshTokenValiditySeconds(7 * 24 * 3600 * 1000)
                    .setScoped(false);
            oauthClientRepository.save(mobileClient);

            OauthClient thirdClient = new OauthClient()
                    .setClientId(Constant.OAUTH_CLIENT_ID_THIRD)
                    .setClientSecret(passwordEncoder.encode(Constant.GLOBAL_DEFAULT_PASSWORD))
                    .setResourceIds(Sets.newHashSet(resourceIds))
                    .setAuthorizedGrantTypes(Sets.newHashSet(grantTypes[0], grantTypes[1]))
                    .setScope(Sets.newHashSet(Constant.OAUTH_CLIENT_ID_THIRD))
                    .setSecretRequired(true)
                    .setAccessTokenValiditySeconds(7 * 24 * 3600 * 1000)
                    .setRefreshTokenValiditySeconds(7 * 24 * 3600 * 1000)
                    .setScoped(false);
            oauthClientRepository.save(thirdClient);
        }
    }

    /**
     * 初始化角色数据 <br/>
     */
    private void initRoleData() {
        Optional<Role> optionalRole = roleRepository.findByCode(Constant.SUPER_ADMIN_ROLE_CODE);
        if (!optionalRole.isPresent()) {
            superAdminRole = new Role(Constant.SUPER_ADMIN_ROLE_CODE, "系统管理员", DataType.INTERNAL, ControlRange.SYSTEM, ModuleType.BASE);
            tenantAdminRole = new Role(Constant.TENANT_ADMIN_ROLE_CODE, "租户管理员", DataType.INTERNAL, ControlRange.TENANT, ModuleType.BASE);
            projectAdminRole = new Role(Constant.PROJECT_ADMIN_ROLE_CODE, "项目管理员", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.BASE);

            // 项目经理
            Role projectManagerRole = new Role("ROLE_000004", "项目经理", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.ESTATE);
            // 保安部负责人
            Role publicSecurityManagerRole = new Role("ROLE_000005", "保安部负责人", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.ESTATE);
            // 保安部员工
            Role publicSecurityEmployeeRole = new Role("ROLE_000006", "保安部员工", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.ESTATE);
            // 保洁部门责任人
            Role cleaningManagerRole = new Role("ROLE_000007", "保洁部门责任人", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.ESTATE);
            // 保洁部员工
            Role cleaningEmployeeRole = new Role("ROLE_000008", "保洁部员工", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.ESTATE);
            // 环境部负责人
            Role environmentManagerRole = new Role("ROLE_000009", "环境部负责人", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.ESTATE);
            // 环境部员工
            Role environmentEmployeeRole = new Role("ROLE_000010", "环境部员工", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.ESTATE);
            // 工程部负责人
            Role engineerManagerRole = new Role("ROLE_000011", "工程部负责人", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.ESTATE);
            // 值班工程师
            Role engineerOnDutyRole = new Role("ROLE_000012", "值班工程师", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.ESTATE);
            // 工程部员工
            Role engineerEmployeeRole = new Role("ROLE_000013", "工程部员工", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.ESTATE);
            // 客服部负责人
            Role customerManagerRole = new Role("ROLE_000014", "客服部负责人", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.ESTATE);
            // 客服部员工
            Role customerEmployeeRole = new Role("ROLE_000015", "客服部员工", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.ESTATE);
            // 安全部负责人
            Role safetyManagerRole = new Role("ROLE_000016", "安全部负责人", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.ESTATE);
            // 安全部员工
            Role safetyEmployeeRole = new Role("ROLE_000017", "安全部员工", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.ESTATE);
            // 品质部负责人
            Role qualityManagerRole = new Role("ROLE_000018", "品质部负责人", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.ESTATE);
            // 品质部员工
            Role qualityEmployeeRole = new Role("ROLE_000019", "品质部员工", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.ESTATE);
            // 财务主管
            Role changeManagerRole = new Role("ROLE_000020", "财务主管", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.ESTATE);
            // 财务专员
            Role changeEmployeeRole = new Role("ROLE_000021", "财务专员", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.ESTATE);
            // 人事部负责人
            Role personalManagerRole = new Role("ROLE_000022", "人事部负责人", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.ESTATE);
            // 人事部员工
            Role personalEmployeeRole = new Role("ROLE_000023", "人事部员工", DataType.INTERNAL, ControlRange.PROJECT, ModuleType.ESTATE);

            roleRepository.saveAll(Lists.newArrayList(superAdminRole, tenantAdminRole, projectAdminRole,
                    projectManagerRole, publicSecurityManagerRole, publicSecurityEmployeeRole, cleaningManagerRole, cleaningEmployeeRole,
                    environmentManagerRole, environmentEmployeeRole, engineerManagerRole, engineerOnDutyRole, engineerEmployeeRole, customerManagerRole,
                    customerEmployeeRole, safetyManagerRole, safetyEmployeeRole, qualityManagerRole, qualityEmployeeRole, changeManagerRole, changeEmployeeRole,
                    personalManagerRole, personalEmployeeRole
            ));
        }
    }

    /**
     * 初始化资源信息
     */
    private void initAuthorities() {
        Optional<Authority> rootAuthority = authorityRepository.findByCode("SAB_000000000000");
        if (!rootAuthority.isPresent()) {
            // 初始化系统级别的资源 SA_
            Authority sabRoot = new Authority(null, "SAB_000000000000", "SaaSManagerCenter", "SaaS管理中心", AuthorityType.MENU, ControlRange.SYSTEM, ModuleType.BASE, null, "/", null, null, "../layouts/BasicLayout", 1);
            Authority sab001 = new Authority(sabRoot, "SAB_010000000000", "welcome", "首页", AuthorityType.MENU, ControlRange.SYSTEM, ModuleType.BASE, null, "/welcome", "icon-home", null, "./Welcome", 1);
            Authority sab002 = new Authority(sabRoot, "SAB_020000000000", "saaSManagement", "SaaS管理", AuthorityType.MENU, ControlRange.SYSTEM, ModuleType.BASE, null, "/saaSManagement", "icon-saas", null, null, 2);
            Authority sab002001 = new Authority(sab002, "SAB_020100000000", "tenantManagement", "租户管理", AuthorityType.MENU, ControlRange.SYSTEM, ModuleType.BASE, null, "/saaSManagement/tenantManagement", null, null, "./saaSManagement/tenantManagement", 1);
            Authority sab002002 = new Authority(sab002, "SAB_020200000000", "NewTenants", "新建租户", AuthorityType.MENU, ControlRange.SYSTEM, ModuleType.BASE, null, "/saaSManagement/tenantManagement/NewTenants", null, true, "./saaSManagement/tenantManagement/components/NewTenants", 2);
            Authority sab002003 = new Authority(sab002, "SAB_020300000000", "UpDate", "更新租户", AuthorityType.MENU, ControlRange.SYSTEM, ModuleType.BASE, null, "/saaSManagement/tenantManagement/UpDate", null, true, "./saaSManagement/tenantManagement/components/UpDate", 3);

            Authority sab003 = new Authority(sabRoot, "SAB_030000000000", "userCenter", "用户中心", AuthorityType.MENU, ControlRange.SYSTEM, ModuleType.BASE, null, "/userCenter", "icon-HR", null, null, 3);
            Authority sab003001 = new Authority(sab003, "SAB_030100000000", "userManagement", "用户管理", AuthorityType.MENU, ControlRange.SYSTEM, ModuleType.BASE, null, "/userCenter/userManagement", null, null, "./saaSManagement/userCenter/userManagement", 1);
            Authority sab003002 = new Authority(sab003, "SAB_030200000000", "builtInConfiguration", "内置角色配置", AuthorityType.MENU, ControlRange.SYSTEM, ModuleType.BASE, null, "/userCenter/builtInConfiguration", null, null, "./saaSManagement/userCenter/builtInConfiguration", 2);

            List<Authority> authorityList = Lists.newArrayList(
                    sabRoot, sab001, sab002, sab003,
                    sab002001, sab002002, sab002003,
                    sab003001, sab003002
            );

            // 初始化租户级别的资源 TA_
            Authority tabRoot = new Authority(null, "TAB_000000000000", "orgManager", "集团管理", AuthorityType.MENU, ControlRange.TENANT, ModuleType.BASE, null, "/", null, null, "../layouts/BasicLayout", 1);
            Authority tab001 = new Authority(tabRoot, "TAB_010000000000", "welcome", "首页", AuthorityType.MENU, ControlRange.TENANT, ModuleType.BASE, null, "/welcome", "icon-home", null, "./Welcome", 1);
            Authority tab002 = new Authority(tabRoot, "TAB_020000000000", "GroupManagement", "组织管理", AuthorityType.MENU, ControlRange.TENANT, ModuleType.BASE, null, "/GroupManagement", "icon-group", null, null, 2);
            Authority tab002001 = new Authority(tab002, "TAB_020100000000", "PersonnelManagement", "人员管理", AuthorityType.MENU, ControlRange.TENANT, ModuleType.BASE, null, "/GroupManagement/GroupOrganization/PersonnelManagement", null, null, "./GroupManagement/GroupOrganization/PersonnelManagement", 1);
            Authority tab002002 = new Authority(tab002, "TAB_020200000000", "RoleSetting", "角色设置", AuthorityType.MENU, ControlRange.TENANT, ModuleType.BASE, null, "/GroupManagement/GroupOrganization/RoleSetting", null, null, "./GroupManagement/GroupOrganization/RoleSetting", 2);
            Authority tab002003 = new Authority(tab002, "TAB_020300000000", "OrganizationalStructure", "组织机构管理", AuthorityType.MENU, ControlRange.TENANT, ModuleType.BASE, null, "/GroupManagement/GroupOrganization/OrganizationalStructureManagement", null, null, "./GroupManagement/GroupOrganization/OrganizationalStructureManagement", 3);

            Authority tab003 = new Authority(tabRoot, "TAB_030000000000", "projectManagement", "项目管理", AuthorityType.MENU, ControlRange.TENANT, ModuleType.BASE, null, "/projectManagement", "icon-project", null, null, 3);
            Authority tab003001 = new Authority(tab003, "TAB_030100000000", "project", "项目管理", AuthorityType.MENU, ControlRange.TENANT, ModuleType.BASE, null, "/projectManagement/GroupOrganization/projectManagement", null, null, "./GroupManagement/GroupOrganization/projectManagement", 1);
            Authority tab003002 = new Authority(tab003, "TAB_030200000000", "AddForm", "新增项目", AuthorityType.MENU, ControlRange.TENANT, ModuleType.BASE, null, "/projectManagement/GroupOrganization/projectManagement/AddForm", null, true, "./GroupManagement/GroupOrganization/projectManagement/components/AddForm", 2);
            Authority tab003003 = new Authority(tab003, "TAB_030300000000", "EditForm", "编辑项目", AuthorityType.MENU, ControlRange.TENANT, ModuleType.BASE, null, "/projectManagement/GroupOrganization/projectManagement/EditForm", null, true, "./GroupManagement/GroupOrganization/projectManagement/components/EditForm", 3);

            authorityList.addAll(Lists.newArrayList(
                    tabRoot, tab001, tab002, tab003,
                    tab002001, tab002002, tab002003,
                    tab003001, tab003002, tab003003
            ));

            // 初始化项目级别的资源 PA_
            Authority paeRoot = new Authority(null, "PAE_000000000000", "estate", "智慧物业", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/", null, null, "../layouts/BasicLayout", 1);
            // 首页
            Authority pae001 = new Authority(paeRoot, "PAE_010000000000", "homePage", "首页", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/homePage", "icon-home", null, "./homePage", 1);
            Authority pae001001 = new Authority(pae001, "PAE_010100000000", "NotificationAnnouncementPage", "通知页面", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/homePage/NotificationAnnouncementPage", null, true, "./homePage/components/NotificationAnnouncementPage", 1);
            Authority pae001002 = new Authority(pae001, "PAE_010200000000", "BacklogList", "待办事项页面", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/homePage/BacklogList", null, true, "./homePage/components/BacklogList", 2);
//        // 组织架构
//        Authority pae001 = new Authority(tabRoot, "PAE_080000000000", "GroupManagement", "组织管理", AuthorityType.MENU, ControlRange.TENANT, ModuleType.BASE, null, "/GroupManagement", "icon-group", null, null, 1);
//        Authority pae001001 = new Authority(tab002, "PAE_080100000000", "PersonnelManagement", "人员管理", AuthorityType.MENU, ControlRange.TENANT, ModuleType.BASE, null, "/GroupManagement/GroupOrganization/PersonnelManagement", null, null, "./GroupManagement/GroupOrganization/PersonnelManagement", 1);
//        Authority pae001002 = new Authority(tab002, "PAE_080200000000", "OrganizationalStructure", "组织机构管理", AuthorityType.MENU, ControlRange.TENANT, ModuleType.BASE, null, "/GroupManagement/GroupOrganization/OrganizationalStructureManagement", null, null, "./GroupManagement/GroupOrganization/OrganizationalStructureManagement", 2);
//
            authorityList.addAll(Lists.newArrayList(
                    paeRoot, pae001, pae001001, pae001002
            ));


            // 综合巡检
            Authority pae004 = new Authority(paeRoot, "PAE_040000000000", "sceneManage", "综合巡检", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/scene", "icon-scene", null, null, 2);
            Authority pae004002 = new Authority(pae004, "PAE_040200000000", "baseSetting", "基础设置", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/scene/baseSetting", null, null, null, 2);
            Authority pae004002001 = new Authority(pae004002, "PAE_040200010000", "pointSet", "点位设置", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/scene/baseSetting/pointSet", null, null, "./pointSet", 1);
            Authority pae004002002 = new Authority(pae004002, "PAE_040200020000", "polling", "巡检路线", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/scene/baseSetting/polling", null, null, "./polling", 2);
            Authority pae004002003 = new Authority(pae004002, "PAE_040200030000", "pollingStandard", "巡检标准", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/scene/baseSetting/pollingStandard", null, null, "./pollingStandard", 3);
            Authority pae004002004 = new Authority(pae004002, "PAE_040200040000", "jobManagement", "巡检作业", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/scene/baseSetting/jobManagement", null, null, "./jobManagement", 4);

            Authority pae004003 = new Authority(pae004, "PAE_040300000000", "checkManage", "巡检管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/scene/checkManage", null, null, null, 3);
            Authority pae004003001 = new Authority(pae004003, "PAE_040300010000", "jobplan", "巡检计划", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/scene/checkManage/jobplan", null, null, "/scene/checkManage/jobplan", 1);
            Authority pae004003002 = new Authority(pae004003, "PAE_040300020000", "patrolRecord", "巡检记录", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/scene/checkManage/patrolRecord", null, null, "./patrolRecord", 2);

            authorityList.addAll(Lists.newArrayList(
                    pae004, pae004002, pae004002001, pae004002002, pae004002003, pae004002004,
                    pae004003, pae004003001, pae004003002

            ));

            // 品质核查
            Authority pae011 = new Authority(paeRoot, "PAE_110000000000", "qualityCheck", "品质核查", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/qualityCheck", "icon-quality-check", null, null, 3);
            Authority pae011001 = new Authority(pae011, "PAE_110100000000", "baseSet", "基础设置", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/qualityCheck/baseSet", null, null, null, 1);

            Authority pae011001001 = new Authority(pae011001, "PAE_110100010000", "qualityCheckStandard", "核查标准", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/qualityCheck/baseSet/qualityCheckStandard", null, null, "./qualityCheckStandard", 1);
            Authority pae011001002 = new Authority(pae011001, "PAE_110100020000", "add", "新增标准", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/qualityCheck/baseSet/qualityCheckStandard/add", null, true, "./qualityCheckStandard/components/AddForm", 2);
            Authority pae011001003 = new Authority(pae011001, "PAE_110100030000", "update", "更新标准", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/qualityCheck/baseSet/qualityCheckStandard/update", null, true, "/qualityCheck/baseSet/qualityCheckStandard/update", 3);
            Authority pae011001004 = new Authority(pae011001, "PAE_110100040000", "qualityCheckWork", "核查作业", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/qualityCheck/baseSet/qualityCheckWork", null, null, "/qualityCheck/baseSet/qualityCheckWork", 4);

            Authority pae011002 = new Authority(pae011, "PAE_110200000000", "checkTask", "核查管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/qualityCheck/checkTask", null, null, null, 2);
            Authority pae011002001 = new Authority(pae011002, "PAE_110200010000", "qualityCheckPlan", "核查计划", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/qualityCheck/checkTask/qualityCheckPlan", null, null, "./qualityCheckPlan", 1);
            Authority pae011002002 = new Authority(pae011002, "PAE_110200020000", "taskList", "任务列表", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/qualityCheck/checkTask/qualityCheckPlan/taskList", null, true, "./qualityCheckPlan/components/TaskTableList", 2);
            Authority pae011002003 = new Authority(pae011002, "PAE_110200030000", "qualityCheckTask", "核查记录", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/qualityCheck/checkTask/qualityCheckTask", null, null, "./qualityCheckTask", 3);
            Authority pae011002004 = new Authority(pae011002, "PAE_110200040000", "qualityCheckRectificationRecord", "整改记录", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/qualityCheck/checkTask/qualityCheckRectificationRecord", null, null, "./qualityCheckRectificationRecord", 4);

            authorityList.addAll(Lists.newArrayList(
                    pae011, pae011001, pae011001001, pae011001002, pae011001003, pae011001004,
                    pae011002, pae011002001, pae011002002, pae011002003, pae011002004

            ));

            // 客户服务
            Authority pae002 = new Authority(paeRoot, "PAE_020000000000", "serviceManage", "客服管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/serviceManage", "icon-customer-service", null, null, 4);
            Authority pae002001 = new Authority(pae002, "PAE_020100000000", "eventoverview", "事件总览", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/serviceManage/eventoverview/:phone/", null, null, "./eventoverview", 1);
            Authority pae002002 = new Authority(pae002, "PAE_020200000000", "customerVisit", "客户回访", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/serviceManage/customerVisit/:status", null, null, "./customerVisit", 2);
            Authority pae002003 = new Authority(pae002, "PAE_020300000000", "servicequestionnaire", "调查问卷", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/serviceManage/servicequestionnaire", null, null, "./servicequestionnaire", 3);
            Authority pae002004 = new Authority(pae002, "PAE_020400000000", "details", "工单详情", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/serviceManage/customerVisit/detailsWork/:id/", null, true, "./customerVisit/detailsWork", 4);
            Authority pae002005 = new Authority(pae002, "PAE_020500000000", "details", "事件详情", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/serviceManage/eventoverview/details/:id/", null, true, "./eventoverview/details", 5);
            Authority pae002006 = new Authority(pae002, "PAE_020600000000", "solvngDetails", "事件详情", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/serviceManage/eventoverview/solvngDetails/:id/:status/", null, true, "./eventoverview/solvngDetails", 6);
            Authority pae002007 = new Authority(pae002, "PAE_020700000000", "closeDetail", "关闭事件详情", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/serviceManage/eventoverview/closeDetail/:id/:status/", null, true, "./eventoverview/closeDetail", 7);
            Authority pae002008 = new Authority(pae002, "PAE_020800000000", "addEvent", "新增事件", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/serviceManage/eventoverview/addEvent/:status/", null, true, "./eventoverview/addEvent", 8);
            Authority pae002009 = new Authority(pae002, "PAE_020900000000", "details", "客户回访事件详情", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/serviceManage/customerVisit/details/:id/", null, true, "./customerVisit/details", 9);
            Authority pae002010 = new Authority(pae002, "PAE_021000000000", "customercall", "客户回访", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/serviceManage/customercall/:telephone/", null, true, "./eventoverview/customercall", 10);
            Authority pae002011 = new Authority(pae002, "PAE_021100000000", "addWork", "新增工单", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/serviceManage/addWork/", null, true, "./workList/components/AddForm", 11);

            authorityList.addAll(Lists.newArrayList(
                    pae002, pae002001, pae002002, pae002003, pae002004, pae002005, pae002006, pae002007, pae002008, pae002009, pae002010, pae002011
            ));

            // 工单管理
            Authority pae003 = new Authority(paeRoot, "PAE_030000000000", "workManage", "工单管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/work", "icon-work-order", null, null, 5);
            Authority pae003001 = new Authority(pae003, "PAE_030100000000", "baseSet", "基础设置", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/work/baseSet", null, null, null, 1);
            Authority pae003001001 = new Authority(pae003001, "PAE_030101000000", "orderType", "工单类型", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/work/baseSet/orderType", null, null, "./workOrderType", 1);
            Authority pae003001002 = new Authority(pae003001, "PAE_030102000000", "slaService", "工单预警", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/work/baseSet/slaService", null, null, "./slaService", 2);
            Authority pae003002 = new Authority(pae003, "PAE_030200000000", "allWorkOrder", "工单管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/work/allWorkOrder", null, null, "./workList", 2);
            Authority pae003003 = new Authority(pae003, "PAE_030300000000", "dataCompute", "数据计算", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/work/dataCompute", null, true, "./404", 3);
            Authority pae003004 = new Authority(pae003, "PAE_030400000000", "workOrderDetail", "工单详情", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/work/allWorkOrder/workOrderDetail/:workOrderId/:workOrderCode/:status", null, true, "./workOrderDetail", 3);

            authorityList.addAll(Lists.newArrayList(
                    pae003, pae003001, pae003001001, pae003001002, pae003002, pae003003, pae003004
            ));

            // 二装管理
            Authority pae007 = new Authority(paeRoot, "PAE_070000000000", "twoPackManagement", "二装管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/twoPackManagement", "icon-second-decoration", null, null, 6);
            Authority pae007001 = new Authority(pae007, "PAE_070100000000", "basicSettings", "基础设置", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/twoPackManagement/basicSettings", null, null, null, 1);
            Authority pae007001001 = new Authority(pae007001, "PAE_070101000000", "decorationType", "装修类型", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/twoPackManagement/basicSettings/decorationType", null, null, "./twoPackManagement/basicSettings/decorationType/index", 1);
            Authority pae007001002 = new Authority(pae007001, "PAE_070102000000", "decorationManagementInformation", "装修资料", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/twoPackManagement/basicSettings/decorationManagementInformation", null, null, "./twoPackManagement/basicSettings/decorationManagementInformation/index", 2);
            Authority pae007002 = new Authority(pae007, "PAE_070200000000", "twoEquipmentManage", "二装管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/twoPackManagement/twoEquipmentManage", null, null, null, 2);
            Authority pae007002001 = new Authority(pae007002, "PAE_070201000000", "decorationRegistration", "装修管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/twoPackManagement/twoEquipmentManage/decorationRegistration", null, null, "./twoPackManagement/twoEquipmentManage/decorationRegistration/index.js", 1);
            Authority pae007002002 = new Authority(pae007002, "PAE_070202000000", "registerDetails", "装修管理详情", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/twoPackManagement/twoEquipmentManage/decorationRegistration/registerDetails", null, true, "./twoPackManagement/twoEquipmentManage/decorationRegistration/components/RegisterDetails", 2);
            Authority pae007002003 = new Authority(pae007002, "PAE_070203000000", "decorationReview", "装修审核", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/twoPackManagement/twoEquipmentManage/decorationReview", null, null, "./twoPackManagement/twoEquipmentManage/decorationReview/index.js", 3);
            Authority pae007002004 = new Authority(pae007002, "PAE_070204000000", "decorationViolation", "装修违章", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/twoPackManagement/twoEquipmentManage/decorationViolation", null, null, "./twoPackManagement/twoEquipmentManage/decorationViolation/index.js", 4);
            Authority pae007002005 = new Authority(pae007002, "PAE_070205000000", "decorationDetails", "详情", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/twoPackManagement/twoEquipmentManage/decorationReview/decorationDetails", null, true, "./twoPackManagement/twoEquipmentManage/decorationReview/components/DecorationDetail", 5);
            Authority pae007002006 = new Authority(pae007002, "PAE_070206000000", "queryDecoration", "装修查询", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/twoPackManagement/twoEquipmentManage/queryDecoration", null, null, "./twoPackManagement/twoEquipmentManage/queryDecoration/index", 6);
            Authority pae007002007 = new Authority(pae007002, "PAE_070207000000", "dataArchiving", "资料归档", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/twoPackManagement/twoEquipmentManage/dataArchiving", null, null, "./twoPackManagement/twoEquipmentManage/dataArchiving/index", 7);
            Authority pae007002008 = new Authority(pae007002, "PAE_070208000000", "dataArchivingDetail", "详情", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/twoPackManagement/twoEquipmentManage/dataArchiving/dataArchivingDetail", null, true, "./twoPackManagement/twoEquipmentManage/dataArchiving/components/dataArchivingDetail", 8);
            Authority pae007002009 = new Authority(pae007002, "PAE_070209000000", "decorationViolationDetail", "详情", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/twoPackManagement/twoEquipmentManage/decorationViolation/decorationViolationDetail/:applicationId/:inspectionId/:breachId", null, true, "./twoPackManagement/twoEquipmentManage/decorationViolation/components/decorationViolationDetail", 9);
            Authority pae007002010 = new Authority(pae007002, "PAE_070210000000", "queryDecorationDetail", "查询详情", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/twoPackManagement/twoEquipmentManage/queryDecoration/queryDecorationDetail", null, true, "./twoPackManagement/twoEquipmentManage/queryDecoration/components/queryDecorationDetail", 10);

            authorityList.addAll(Lists.newArrayList(
                    pae007, pae007001, pae007001001, pae007001002, pae007002,
                    pae007002001, pae007002002, pae007002003, pae007002004, pae007002005,
                    pae007002006, pae007002007, pae007002008, pae007002009, pae007002010
            ));

            // 设备管理
            Authority pae005 = new Authority(paeRoot, "PAE_050000000000", "deviceManage", "设备管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/deviceManage", "icon-device", null, null, 7);
            Authority pae005001 = new Authority(pae005, "PAE_050100000000", "basicSettings", "基础设置", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/deviceManage/basicSettings", null, null, null, 1);
            Authority pae005001001 = new Authority(pae005001, "PAE_050101000000", "deviceType", "设备类别", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/deviceManage/basicSettings/deviceType", null, null, "./deviceType", 1);
            Authority pae005001002 = new Authority(pae005001, "PAE_050102000000", "deviceInspectionStandard", "巡检标准", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/deviceManage/basicSettings/deviceInspectionStandard", null, null, "./deviceInspectionStandard", 2);
            Authority pae005001003 = new Authority(pae005001, "PAE_050103000000", "deviceMaintain", "保养标准", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/deviceManage/basicSettings/deviceMaintain", null, null, "./deviceMaintain", 3);
            Authority pae005001004 = new Authority(pae005001, "PAE_0501040000000", "deviceJobmanagement", "作业管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/deviceManage/basicSettings/deviceJobmanagement", null, null, "./deviceJobmanagement", 4);
            Authority pae005002 = new Authority(pae005, "PAE_050200000000", "deviceManagement", "设备档案", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/deviceManage/deviceManagement", null, null, null, 2);
            Authority pae005002001 = new Authority(pae005002, "PAE_050201000000", "device", "设备档案", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/deviceManage/deviceManagement/device", null, null, "./device", 1);
            Authority pae005002002 = new Authority(pae005002, "PAE_050202000000", "watch", "表具管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/deviceManage/deviceManagement/watch", null, null, "./watch", 2);
            Authority pae005003 = new Authority(pae005, "PAE_050300000000", "deviceInspectionManagement", "设备巡检", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/deviceManage/deviceInspectionManagement", null, null, null, 3);
            Authority pae005003001 = new Authority(pae005003, "PAE_050301000000", "Inspectionplan", "巡检计划", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/deviceManage/deviceInspectionManagement/Inspectionplan", null, null, "./deviceInspectionPlan", 1);
            Authority pae005003002 = new Authority(pae005003, "PAE_050302000000", "InspectionrRecord", "巡检记录", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/deviceManage/deviceInspectionManagement/InspectionrRecord", null, null, "./deviceInspectionrRecord", 2);
            Authority pae005003003 = new Authority(pae005003, "PAE_050303000000", "deviceInspectionPlanSpectaculars", "计划看板", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/deviceManage/deviceInspectionManagement/deviceInspectionPlanSpectaculars", null, true, "./deviceInspectionPlanSpectaculars", 3);

            Authority pae005004 = new Authority(pae005, "PAE_050400000000", "deviceEquipmentMaintenance", "设备维保", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/deviceManage/deviceEquipmentMaintenance", null, null, null, 4);
            Authority pae005004001 = new Authority(pae005004, "PAE_050401000000", "Maintenanceplan", "维保计划", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/deviceManage/deviceEquipmentMaintenance/Maintenanceplan", null, null, "./deviceMaintenanceplan", 1);
            Authority pae005004002 = new Authority(pae005004, "PAE_050402000000", "Maintenancerecord", "维保记录", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/deviceManage/deviceEquipmentMaintenance/Maintenancerecord", null, null, "./deviceMaintenancerecord", 2);

            authorityList.addAll(Lists.newArrayList(
                    pae005, pae005001, pae005001001, pae005001002, pae005001003, pae005001004,
                    pae005002, pae005002001, pae005002002, pae005003, pae005003001, pae005003002, pae005003003,
                    pae005004, pae005004001, pae005004002
            ));


            // 收费管理
            Authority pae006 = new Authority(paeRoot, "PAE_060000000000", "financeManage", "收费管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/financeManage", "icon-finance", null, null, 8);
            Authority pae006001 = new Authority(pae006, "PAE_060100000000", "receivable", "应收管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/financeManage/receivable", null, null, null, 1);
            Authority pae006001001 = new Authority(pae006001, "PAE_060101000000", "receivableContract", "合同管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/financeManage/receivable/receivableContract", null, null, "./receivableContract", 1);
            Authority pae006001002 = new Authority(pae006001, "PAE_060102000000", "addReceivableContract", "新建合同", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/financeManage/receivable/receivableContract/addReceivableContract", null, true, "./receivableContract", 2);
            Authority pae006001003 = new Authority(pae006001, "PAE_060103000000", "updateReceivableContract", "查看合同", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/financeManage/receivable/receivableContract/updateReceivableContract/:chargeId/:contractId", null, true, "./receivableContract/components/UpdateForm", 3);
            Authority pae006001004 = new Authority(pae006001, "PAE_060104000000", "ladderRate", "费率管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/financeManage/receivable/ladderRate", null, null, "./ladderRate", 4);
            Authority pae006001005 = new Authority(pae006001, "PAE_060105000000", "addLadderRate", "新建费率表", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/financeManage/receivable/ladderRate/addLadderRate", null, true, "./ladderRate/components/AddForm", 5);
            Authority pae006001006 = new Authority(pae006001, "PAE_060106000000", "updateLadderRate", "编辑费率表", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/financeManage/receivable/ladderRate/updateLadderRate", null, true, "./ladderRate/components/UpdateForm", 6);
            Authority pae006001007 = new Authority(pae006001, "PAE_060107000000", "receivableDetails", "应收明细", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/financeManage/receivable/receivableDetails", null, null, "./receivableDetails", 7);
            Authority pae006001008 = new Authority(pae006001, "PAE_060108000000", "receivableDetail", "查看合同应收明细", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/financeManage/receivable/receivableDetails/receivableDetail", null, true, "./receivableDetails/components/DetailForm", 8);
            Authority pae006001009 = new Authority(pae006001, "PAE_060109000000", "meterReading", "能源抄表", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/financeManage/receivable/meterReading", null, null, "./meterReading", 9);
            Authority pae006001010 = new Authority(pae006001, "PAE_060110000000", "meterReadingDetail", "查看业主能源表抄表", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/financeManage/receivable/meterReading/meterReadingDetail", null, true, "./meterReading/components/DetailForm", 10);
            Authority pae006001011 = new Authority(pae006001, "PAE_060111000000", "receivableCostFlow", "费用流水", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/financeManage/receivable/receivableCostFlow", null, null, "./receivableCostFlow", 11);
            Authority pae006002 = new Authority(pae006, "PAE_060200000000", "payable", "应付管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/financeManage/payable", null, null, null, 2);
            Authority pae006002001 = new Authority(pae006002, "PAE_060201000000", "payableContract", "合同管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/financeManage/payable/payableContract", null, null, "./payableContract", 1);
            Authority pae006002002 = new Authority(pae006002, "PAE_060202000000", "addPayableContract", "新建合同", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/financeManage/payable/payableContract/addPayableContract", null, true, "./payableContract/components/AddForm", 2);
            Authority pae006002003 = new Authority(pae006002, "PAE_060203000000", "updatePayableContract", "查看合同", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/financeManage/payable/payableContract/updatePayableContract", null, true, "./payableContract/components/UpdateForm", 3);
            Authority pae006002004 = new Authority(pae006002, "PAE_060204000000", "payableDetails", "应付明细", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/financeManage/payable/payableDetails", null, null, "./payableDetails", 4);
            Authority pae006002005 = new Authority(pae006002, "PAE_060205000000", "payableDetail", "查看合同应付明细", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/financeManage/payable/payableDetails/payableDetail", null, true, "./payableDetails/components/DetailForm", 5);
            Authority pae006002006 = new Authority(pae006002, "PAE_060206000000", "payableCostFlow", "费用流水", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/financeManage/payable/payableCostFlow", null, null, "./payableCostFlow", 6);

            authorityList.addAll(Lists.newArrayList(
                    pae006, pae006001, pae006002,
                    pae006001001, pae006001002, pae006001003, pae006001004, pae006001005,
                    pae006001006, pae006001007, pae006001008, pae006001009, pae006001010, pae006001011,
                    pae006002001, pae006002002, pae006002003, pae006002004, pae006002005, pae006002006
            ));

            // 资源管理
            Authority pae009 = new Authority(paeRoot, "PAE_090000000000", "resourceManage", "资源管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/resourceManage", "icon-resource", null, null, 9);
            Authority pae009001 = new Authority(pae009, "PAE_090100000000", "purchasingManagement", "采购管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/resourceManage/purchasingManagement", null, null, null, 1);
            Authority pae009001001 = new Authority(pae009001, "PAE_090101000000", "materialApplication", "物料申请单", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/resourceManage/purchasingManagement/materialApplication", null, null, "./materialApplication", 1);
            Authority pae009001002 = new Authority(pae009001, "PAE_090102000000", "supplier", "供应商管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/resourceManage/purchasingManagement/supplier", null, null, "./supplier", 2);
            Authority pae009001003 = new Authority(pae009001, "PAE_090103000000", "inquiryPrice", "询报价单", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/resourceManage/purchasingManagement/inquiryPrice", null, null, "./inquiryPrice", 3);
            Authority pae009001004 = new Authority(pae009001, "PAE_090104000000", "purchaseOrder", "采购订单", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/resourceManage/purchasingManagement/purchaseOrder", null, null, "./purchaseOrder", 4);
            Authority pae009002 = new Authority(pae009, "PAE_090200000000", "materialManagement", "物料管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/resourceManage/materialManagement", null, null, null, 2);
            Authority pae009002001 = new Authority(pae009002, "PAE_090201000000", "inStockManagement", "入库管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/resourceManage/materialManagement/inStockManagement", null, null, "./inStockManagement", 1);
            Authority pae009002002 = new Authority(pae009002, "PAE_090202000000", "outStockManagement", "出库管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/resourceManage/materialManagement/outStockManagement", null, null, "./outStockManagement", 2);
            Authority pae009002003 = new Authority(pae009002, "PAE_090203000000", "stockAllocation", "库存调拨", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/resourceManage/materialManagement/stockAllocation", null, null, "./stockAllocation", 3);
            Authority pae009002004 = new Authority(pae009002, "PAE_090204000000", "stockCheck", "库存盘点", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/resourceManage/materialManagement/stockCheck", null, null, "./stockCheck", 4);
            Authority pae009002005 = new Authority(pae009002, "PAE_090205000000", "stockQuery", "库存查询", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/resourceManage/materialManagement/stockQuery", null, null, "./stockQuery", 5);
            Authority pae009002006 = new Authority(pae009002, "PAE_090206000000", "stockManagement", "仓库管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/resourceManage/materialManagement/stockManagement", null, null, "./stockManagement", 6);
            Authority pae009002007 = new Authority(pae009002, "PAE_090207000000", "materialType", "物料分类", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/resourceManage/materialManagement/materialType", null, null, "./materialType", 7);
            Authority pae009002008 = new Authority(pae009002, "PAE_090208000000", "materialList", "物料列表", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/resourceManage/materialManagement/materialList", null, null, "./materialList", 8);
            Authority pae009003 = new Authority(pae009, "PAE_090300000000", "property", "资产管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/resourceManage/property", null, null, null, 3);
            Authority pae009003001 = new Authority(pae009003, "PAE_090301000000", "propertyType", "资产分类", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/resourceManage/property/propertyType", null, null, "./propertyType/index", 1);
            Authority pae009003002 = new Authority(pae009003, "PAE_090302000000", "propertyManage", "资产管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/resourceManage/property/propertyManage", null, null, "./propertyManage/index", 2);
            Authority pae009003003 = new Authority(pae009003, "PAE_090303000000", "propertyCheck", "资产盘点", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/resourceManage/property/propertyCheck", null, null, "./propertyCheck/index", 3);

            authorityList.addAll(Lists.newArrayList(
                    pae009, pae009001, pae009002, pae009003,
                    pae009001001, pae009001002, pae009001003, pae009001004,
                    pae009002001, pae009002002, pae009002003, pae009002004, pae009002005, pae009002006, pae009002007, pae009002008,
                    pae009003001, pae009003002, pae009003003
            ));


            // 人事管理
            Authority pae013 = new Authority(paeRoot, "PAE_130000000000", "HRManagement", "人事管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/hr", "icon-HR", null, null, 10);
            Authority pae013001 = new Authority(pae013, "PAE_130100000000", "hrSet", "签到管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/hr/hrSet", null, null, null, 1);
            Authority pae013001001 = new Authority(pae013001, "PAE_130101000000", "newSignGroup", "签到组管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/hr/hrSet/newWorkGroup", null, null, "./newSignGroup/index", 1);
            Authority pae013001002 = new Authority(pae013001, "PAE_130102000000", "checkInReport", "签到报表", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/hr/hrSet/checkInReport", null, null, "./checkInReport/index", 2);
            Authority pae013002 = new Authority(pae013, "PAE_130200000000", "trainingManagement", "培训管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/hr/trainingManagement", null, null, null, 2);
            Authority pae013002001 = new Authority(pae013002, "PAE_130201000000", "trainingNotice", "培训通知", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/hr/trainingManagement/trainingNotice", null, null, "./trainingNotice/index", 1);
            Authority pae013002002 = new Authority(pae013002, "PAE_130202000000", "AddForm", "新建培训通知", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/hr/trainingManagement/trainingNotice/addForm", null, true, "./trainingNotice/components/AddForm", 2);
            Authority pae013002003 = new Authority(pae013002, "PAE_130203000000", "update", "编辑培训通知", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/hr/trainingManagement/trainingNotice/Updata/:id", null, true, "./trainingNotice/components/Updata", 3);
            Authority pae013002004 = new Authority(pae013002, "PAE_130204000000", "trainingCourse", "资产盘点", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/hr/trainingManagement/trainingCourse", null, null, "./trainingCourse/index", 4);
            Authority pae013002005 = new Authority(pae013002, "PAE_130205000000", "addForm", "新建培训课程", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/hr/trainingManagement/trainingCourse/addForm", null, true, "./trainingCourse/components/AddForm", 5);
            Authority pae013002006 = new Authority(pae013002, "PAE_130206000000", "update", "编辑培训课程", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/hr/trainingManagement/trainingCourse/UpdataForm/:id", null, true, "./trainingCourse/components/UpdataForm", 6);

            authorityList.addAll(Lists.newArrayList(
                    pae013, pae013001, pae013002,
                    pae013001001, pae013001002,
                    pae013002001, pae013002002, pae013002003, pae013002004, pae013002005, pae013002006
            ));

            // 安全管理
            Authority pae014 = new Authority(paeRoot, "PAE_140000000000", "safetyManage", "安全管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/safetyManage", "icon-safety", null, null, 11);
            Authority pae014001 = new Authority(pae014, "PAE_140100000000", "safetyCheckManage", "安全检查", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/safetyManage/check", null, null, null, 1);
            Authority pae014001001 = new Authority(pae014001, "PAE_140101000000", "safetyCheckPlan", "安全检查计划", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/safetyManage/check/plan", null, null, "./safetyCheckPlan", 1);
            Authority pae014001002 = new Authority(pae014001, "PAE_140102000000", "checkTaskProgress", "检查任务进度", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/safetyManage/check/taskProgress", null, null, "./checkTaskProgress", 2);
            Authority pae014001003 = new Authority(pae014001, "PAE_140103000000", "hiddenDangerIndex", "隐患指数", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/safetyManage/check/taskProgress/hiddenDangerIndex", null, true, "./checkTaskProgress/components/hiddenDangerIndex", 3);
            Authority pae014001004 = new Authority(pae014001, "PAE_140104000000", "hiddenDangerRectificationRecord", "隐患整改记录", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/safetyManage/check/rectificationRecords", null, null, "./hiddenDangerRectificationRecord", 4);

            Authority pae014002 = new Authority(pae014, "PAE_140200000000", "dangerousJob", "危险作业", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/safetyManage/dangerousJob", null, null, null, 2);
            Authority pae014002001 = new Authority(pae014002, "PAE_140201000000", "dangerousJobManage", "危险作业管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/safetyManage/dangerousJob/manage", null, null, "./dangerousJobManage", 1);
            Authority pae014002002 = new Authority(pae014002, "PAE_140202000000", "addDangerousJob", "新增危险作业", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/safetyManage/dangerousJob/manage/addDangerousJob", null, true, "./dangerousJobManage/components/AddForm", 2);
            Authority pae014002003 = new Authority(pae014002, "PAE_140203000000", "updateDangerousJob", "更新危险作业", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/safetyManage/dangerousJob/manage/updateDangerousJob", null, true, "./dangerousJobManage/components/UpdateForm", 3);
            Authority pae014002004 = new Authority(pae014002, "PAE_140204000000", "dangerousJobDetail", "危险作业详情", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/safetyManage/dangerousJob/manage/dangerousJobDetail", null, true, "./dangerousJobManage/components/DetailForm", 4);
            Authority pae014002005 = new Authority(pae014002, "PAE_140205000000", "dangerousJobCheck", "危险作业审核", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/safetyManage/dangerousJob/Check", null, null, "./dangerousJobCheck", 5);
            Authority pae014002006 = new Authority(pae014002, "PAE_140206000000", "dangerousCheckDetails", "作业审核详情", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/safetyManage/dangerousJob/Check/checkDetails", null, true, "./dangerousJobCheck/components/checkDetails", 6);
            Authority pae014002007 = new Authority(pae014002, "PAE_140207000000", "dangerousJobReview", "危险作业审查", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/safetyManage/dangerousJob/Review", null, null, "./dangerousJobReview", 7);
            Authority pae014002008 = new Authority(pae014002, "PAE_140208000000", "dangerousJobReviewDetails", "作业审查详情", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/safetyManage/dangerousJob/Review/reviewDetails", null, true, "./dangerousJobReview/components/rviewDetails", 8);

            authorityList.addAll(Lists.newArrayList(
                    pae014,
                    pae014001, pae014001001, pae014001002, pae014001003, pae014001004,
                    pae014002, pae014002001, pae014002002, pae014002003, pae014002004, pae014002005, pae014002006, pae014002007, pae014002008
            ));

            // 系统设置
            Authority pae010 = new Authority(paeRoot, "PAE_100000000000", "systemSetting", "系统设置", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab", "icon-system", null, null, 12);
            Authority pae010001 = new Authority(pae010, "PAE_100100000000", "baseManagement", "基础管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/base", null, null, null, 1);
            Authority pae010001001 = new Authority(pae010001, "PAE_100101000000", "spaceManage", "空间管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/base/spaceManage", null, null, "./spaceManage/index", 1);
            Authority pae010001002 = new Authority(pae010001, "PAE_100102000000", "parkingArchives", "车位档案", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/base/parkingArchives", null, null, "./parkingArchives", 2);
            Authority pae010001003 = new Authority(pae010001, "PAE_100103000000", "CustomerList", "客商资料", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/base/CustomerList", null, null, "./customerInformation/components/CustomerList", 3);
            Authority pae010001004 = new Authority(pae010001, "PAE_100104000000", "UpdateInformation", "修改资料", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/base/UpdateInformation", null, true, "./customerInformation/components/UpdateInformation", 4);
            Authority pae010001005 = new Authority(pae010001, "PAE_100105000000", "AddCustomer", "添加客户", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/base/AddCustomer", null, true, "./customerInformation/components/AddCustomer", 5);
            Authority pae010001006 = new Authority(pae010001, "PAE_100106000000", "tenantManage", "业主管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/base/tenantManage", null, null, "./tenantManage/index", 6);
            Authority pae010001007 = new Authority(pae010001, "PAE_100107000000", "spacePlaces", "场地管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/base/spacePlaces", null, null, "./spacePlaces", 7);
            Authority pae010002 = new Authority(pae010, "PAE_100200000000", "commonality", "公共资料", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/commonality", null, null, null, 2);
            Authority pae010002001 = new Authority(pae010002, "PAE_100201000000", "sourceManagement", "危险源管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/commonality/sourceManagement", null, null, "./sourceManagement", 1);
            Authority pae010002002 = new Authority(pae010002, "PAE_100202000000", "certificationManagement", "资格证管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/commonality/certificationManagement", null, null, "./certificationManagement", 2);
            Authority pae010003 = new Authority(pae010, "PAE_100300000000", "workdaymanagement", "工作日管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/workdaymanagement", null, null, null, 3);
            Authority pae010003001 = new Authority(pae010003, "PAE_100301000000", "workdaySetting", "工作日设置", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/workdaymanagement/workdaySetting", null, null, "./workdaySetting/index", 1);
            Authority pae010003002 = new Authority(pae010003, "PAE_100302000000", "WorkingDayList", "工作日一览", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/workdaymanagement/workingDayList", null, null, "./workingDayList", 2);
            Authority pae010004 = new Authority(pae010, "PAE_100400000000", "organizationStructure", "组织管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/projectManagement", null, null, null, 4);
            Authority pae010004001 = new Authority(pae010004, "PAE_100401000000", "PersonnelManagement", "人员管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/projectManagement/ProjectOrganizationStructure/PersonnelManagement", null, null, "./GroupManagement/GroupOrganization/PersonnelManagement", 1);
            Authority pae010004002 = new Authority(pae010004, "PAE_100402000000", "OrganizationalStructure", "组织架构", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/projectManagement/ProjectOrganizationStructure/OrganizationalStructureManagement", null, null, "./GroupManagement/GroupOrganization/OrganizationalStructureManagement", 2);
//        Authority pae010004003 = new Authority(pae010004, "PAE_100403000000", "RoleSetting", "角色设置", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/projectManagement/ProjectOrganizationStructure/RoleSetting", null, null, "./projectManagement/ProjectOrganizationStructure/RoleSetting", 3);

            Authority pae010005 = new Authority(pae010, "PAE_100500000000", "other", "其他", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/other", null, null, null, 5);
            Authority pae010005001 = new Authority(pae010005, "PAE_100501000000", "dataDictionary", "数据字典", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/other/dataDictionary", null, null, "./datadictionary/index", 1);
            Authority pae010005002 = new Authority(pae010005, "PAE_100502000000", "integratedSupervision", "综合监控", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/other/integratedSupervision", null, null, "./integratedSupervision", 2);

            Authority pae010006 = new Authority(pae010, "PAE_100600000000", "programManage", "项目管理", AuthorityType.MENU, ControlRange.PROJECT, ModuleType.ESTATE, null, "/lab/programManage", null, true, "./404", 6);


            authorityList.addAll(Lists.newArrayList(
                    pae010, pae010001, pae010002, pae010003, pae010004, pae010005, pae010006,
                    pae010001001, pae010001002, pae010001003, pae010001004, pae010001005, pae010001006, pae010001007,
                    pae010002001, pae010002002, pae010003001, pae010003002,
                    pae010004001, pae010004002,
                    pae010005001, pae010005002
            ));

            authorityRepository.saveAll(authorityList);

            // 角色赋权
            List<RoleAuthority> roleAuthorityLists = new ArrayList<>();

            // 系统管理员
            roleRepository.findByCode(Constant.SUPER_ADMIN_ROLE_CODE).ifPresent(role -> {
                // 获取系统级别的资源
                List<Authority> systemAuthorities = authorityRepository.findByCodeStartingWith(Constant.SYSTEM_AUTHORITY_CODE_PREFIX);
                systemAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });

            // 租户管理员
            roleRepository.findByCode(Constant.TENANT_ADMIN_ROLE_CODE).ifPresent(role -> {
                // 获取租户级别的资源
                List<Authority> tenantAuthorities = authorityRepository.findByCodeStartingWith(Constant.TENANT_AUTHORITY_CODE_PREFIX);
                tenantAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });

            // 项目管理员
            roleRepository.findByCode(Constant.PROJECT_ADMIN_ROLE_CODE).ifPresent(role -> {
                List<Authority> projectAuthorities = Lists.newArrayList(
                        paeRoot, pae004, pae004002, pae004002001, pae004002002, pae004002003,
                        pae011, pae011001, pae011001001, pae011001002, pae011001003, pae011001004,
                        pae003, pae003001, pae003001001, pae003001002,
                        pae005, pae005001, pae005001001, pae005001002, pae005001003,
                        pae010, pae010001, pae010003, pae010004, pae010005, pae010006,
                        pae010001001, pae010001002, pae010001004, pae010001005, pae010001007,
                        pae010003001, pae010003002, pae010004001, pae010004002, pae010005001, pae010005002);

                projectAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });

            // 项目经理 ROLE_000004 projectManagerRole
            roleRepository.findByCode("ROLE_000004").ifPresent(role -> {
                List<Authority> projectAuthorities = Lists.newArrayList(
                        paeRoot, pae001, pae001001, pae001002,
                        pae004, pae004002, pae004002001, pae004002002, pae004002003, pae004002004, pae004003, pae004003001, pae004003002,
                        pae010, pae010002, pae010002001, pae010002002);
                projectAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });

            // 保安部负责人 ROLE_000005 publicSecurityManagerRole
            roleRepository.findByCode("ROLE_000005").ifPresent(role -> {
                List<Authority> projectAuthorities = Lists.newArrayList(
                        paeRoot, pae001, pae001001, pae001002,
                        pae004, pae004002, pae004002004, pae004003, pae004003001, pae004003002,
                        pae003, pae003002, pae003003, pae003004,
                        pae007, pae007002, pae007002001, pae007002002, pae007002003, pae007002004, pae007002005,
                        pae007002006, pae007002007, pae007002008, pae007002009, pae007002010,
                        pae010, pae010002, pae010002001, pae010002002
                );
                projectAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });
            // 保安部员工 ROLE_000006 publicSecurityEmployeeRole
            roleRepository.findByCode("ROLE_000006").ifPresent(role -> {
                List<Authority> projectAuthorities = Lists.newArrayList(
                        paeRoot, pae001, pae001001, pae001002,
                        pae003, pae003002, pae003003, pae003004,
                        pae007, pae007002, pae007002001, pae007002002, pae007002005,
                        pae007002006, pae007002007, pae007002008, pae007002009, pae007002010,
                        pae010, pae010002, pae010002001, pae010002002
                );
                projectAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });
            // 保洁部门责任人 ROLE_000007 cleaningManagerRole
            roleRepository.findByCode("ROLE_000007").ifPresent(role -> {
                List<Authority> projectAuthorities = Lists.newArrayList(
                        paeRoot, pae001, pae001001, pae001002,
                        pae003, pae003002, pae003003, pae003004,
                        pae004, pae004002, pae004002004, pae004003, pae004003001, pae004003002,
                        pae007, pae007002, pae007002001, pae007002002, pae007002003, pae007002004, pae007002005,
                        pae007002006, pae007002007, pae007002008, pae007002009, pae007002010,
                        pae010, pae010002, pae010002001, pae010002002
                );
                projectAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });
            // 保洁部员工 ROLE_000008 cleaningEmployeeRole
            roleRepository.findByCode("ROLE_000008").ifPresent(role -> {
                List<Authority> projectAuthorities = Lists.newArrayList(
                        paeRoot, pae001, pae001001, pae001002,
                        pae003, pae003002, pae003003, pae003004,
                        pae007, pae007002, pae007002001, pae007002002, pae007002005,
                        pae007002006, pae007002007, pae007002008, pae007002009, pae007002010,
                        pae010, pae010002, pae010002001, pae010002002
                );
                projectAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });
            // 环境部负责人 ROLE_000009 environmentManagerRole
            roleRepository.findByCode("ROLE_000009").ifPresent(role -> {
                List<Authority> projectAuthorities = Lists.newArrayList(
                        paeRoot, pae001, pae001001, pae001002,
                        pae003, pae003002, pae003003, pae003004,
                        pae004, pae004002, pae004002004, pae004003, pae004003001, pae004003002,
                        pae007, pae007002, pae007002001, pae007002002, pae007002003, pae007002004, pae007002005,
                        pae007002006, pae007002007, pae007002008, pae007002009, pae007002010,
                        pae010, pae010002, pae010002001, pae010002002
                );
                projectAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });
            // 环境部员工 ROLE_000010 environmentEmployeeRole
            roleRepository.findByCode("ROLE_000010").ifPresent(role -> {
                List<Authority> projectAuthorities = Lists.newArrayList(
                        paeRoot, pae001, pae001001, pae001002,
                        pae003, pae003002, pae003003, pae003004,
                        pae007, pae007002, pae007002001, pae007002002, pae007002005,
                        pae007002006, pae007002007, pae007002008, pae007002009, pae007002010,
                        pae010, pae010002, pae010002001, pae010002002
                );
                projectAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });
            // 工程部负责人 ROLE_000011 engineerManagerRole
            roleRepository.findByCode("ROLE_000011").ifPresent(role -> {
                List<Authority> projectAuthorities = Lists.newArrayList(
                        paeRoot, pae001, pae001001, pae001002,
                        pae003, pae003002, pae003003, pae003004,
                        pae007, pae007002, pae007002001, pae007002002, pae007002003, pae007002004, pae007002005,
                        pae007002006, pae007002007, pae007002008, pae007002009, pae007002010,
                        pae005, pae005001, pae005001004, pae005002, pae005002001, pae005002002, pae005003, pae005003001, pae005003002, pae005003003, pae005004, pae005004001, pae005004002,
                        pae010, pae010002, pae010002001, pae010002002
                );
                projectAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });
//        // 值班工程师 ROLE_000012 engineerOnDutyRole
//        roleRepository.findByCode("ROLE_000012").ifPresent(role -> {
//            // 获取项目级别的资源
//            List<Authority> projectAuthorities = Lists.newArrayList(pae001, pae001001, pae001002, pae004,
//
//                    );
//            projectAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
//        });
            // 工程部员工 ROLE_000013 engineerEmployeeRole
            roleRepository.findByCode("ROLE_000013").ifPresent(role -> {
                List<Authority> projectAuthorities = Lists.newArrayList(
                        paeRoot, pae001, pae001001, pae001002,
                        pae003, pae003002, pae003003, pae003004,
                        pae007, pae007002, pae007002001, pae007002002, pae007002005,
                        pae007002006, pae007002007, pae007002008, pae007002009, pae007002010,
                        pae005, pae005002, pae005002001, pae005002002, pae005003, pae005003002, pae005003003, pae005004, pae005004002,
                        pae010, pae010002, pae010002001, pae010002002
                );
                projectAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });
            // 客服部负责人 ROLE_000014 customerManagerRole
            roleRepository.findByCode("ROLE_000014").ifPresent(role -> {
                // 获取项目级别的资源
                List<Authority> projectAuthorities = Lists.newArrayList(
                        paeRoot, pae001, pae001001, pae001002,
                        pae002, pae002001, pae002002, pae002003, pae002004, pae002005, pae002006, pae002007, pae002008, pae002009, pae002010, pae002011,
                        pae003, pae003001, pae003001001, pae003001002, pae003002, pae003003, pae003004,
                        pae007, pae007001, pae007001001, pae007001002, pae007002, pae007002001, pae007002002, pae007002003, pae007002004, pae007002005,
                        pae007002006, pae007002007, pae007002008, pae007002009, pae007002010,
                        pae010, pae010002, pae010002001, pae010002002
                );
                projectAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });
            // 客服部员工 ROLE_000015 customerEmployeeRole
            roleRepository.findByCode("ROLE_000015").ifPresent(role -> {
                List<Authority> projectAuthorities = Lists.newArrayList(
                        paeRoot, pae001, pae001001, pae001002,
                        pae002, pae002001, pae002002, pae002004, pae002005, pae002006, pae002007, pae002008, pae002009, pae002010, pae002011,
                        pae003, pae003002, pae003003, pae003004,
                        pae007, pae007002, pae007002001, pae007002002, pae007002005,
                        pae007002006, pae007002007, pae007002008, pae007002009, pae007002010,
                        pae010, pae010002, pae010002001, pae010002002
                );
                projectAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });
            // 安全部负责人 ROLE_000016 safetyManagerRole
            roleRepository.findByCode("ROLE_000016").ifPresent(role -> {
                List<Authority> projectAuthorities = Lists.newArrayList(
                        paeRoot, pae001, pae001001, pae001002,
                        pae014, pae014001, pae014001001, pae014001002, pae014001003, pae014001004,
                        pae014002, pae014002001, pae014002002, pae014002003, pae014002004, pae014002005, pae014002006, pae014002007, pae014002008,
                        pae010, pae010002, pae010002001, pae010002002
                );
                projectAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });
            // 安全部员工 ROLE_000017 safetyEmployeeRole
            roleRepository.findByCode("ROLE_000017").ifPresent(role -> {
                List<Authority> projectAuthorities = Lists.newArrayList(
                        paeRoot, pae001, pae001001, pae001002,
                        pae014, pae014001, pae014001002, pae014001003, pae014001004, pae014002, pae014002001, pae014002002, pae014002003, pae014002004,
                        pae010, pae010002, pae010002001, pae010002002
                );
                projectAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });
            // 品质部负责人 ROLE_000018 qualityManagerRole
            roleRepository.findByCode("ROLE_000018").ifPresent(role -> {
                // 获取项目级别的资源
                List<Authority> projectAuthorities = Lists.newArrayList(pae001, pae001001, pae001002, pae004,
                        paeRoot, pae001, pae001001, pae001002,
                        pae011, pae011001, pae011001004, pae011002, pae011002001, pae011002002, pae011002003, pae011002004,
                        pae010, pae010002, pae010002001, pae010002002
                );
                projectAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });
            // 品质部员工 ROLE_000019 qualityEmployeeRole
            roleRepository.findByCode("ROLE_000019").ifPresent(role -> {
                List<Authority> projectAuthorities = Lists.newArrayList(
                        paeRoot, pae001, pae001001, pae001002,
                        pae011, pae011002, pae011002003, pae011002004,
                        pae010, pae010002, pae010002001, pae010002002
                );
                projectAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });
            // 财务主管 ROLE_000020 changeManagerRole
            roleRepository.findByCode("ROLE_000020").ifPresent(role -> {
                // 获取项目级别的资源
                List<Authority> projectAuthorities = Lists.newArrayList(
                        paeRoot, pae001, pae001001, pae001002,
                        pae006, pae006001, pae006002,
                        pae006001001, pae006001002, pae006001003, pae006001004, pae006001005,
                        pae006001006, pae006001007, pae006001008, pae006001009, pae006001010, pae006001011,
                        pae006002001, pae006002002, pae006002003, pae006002004, pae006002005, pae006002006,
                        pae010, pae010002, pae010002001, pae010002002
                );
                projectAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });
            // 财务专员 ROLE_000021 changeEmployeeRole
            roleRepository.findByCode("ROLE_000021").ifPresent(role -> {
                // 获取项目级别的资源
                List<Authority> projectAuthorities = Lists.newArrayList(
                        paeRoot, pae001, pae001001, pae001002,
                        pae006, pae006001, pae006002, pae006001004, pae006001005, pae006001006, pae006001007,
                        pae006001008, pae006001009, pae006001010, pae006001011, pae006002004, pae006002005, pae006002006,
                        pae010, pae010002, pae010002001, pae010002002
                );
                projectAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });
            // 人事部负责人 ROLE_000022 personalManagerRole
            roleRepository.findByCode("ROLE_000022").ifPresent(role -> {
                List<Authority> projectAuthorities = Lists.newArrayList(
                        paeRoot, pae013, pae013001, pae013002, pae013001001, pae013001002,
                        pae013002001, pae013002002, pae013002003, pae013002004, pae013002005, pae013002006
                );
                projectAuthorities.forEach(authority -> roleAuthorityLists.add(new RoleAuthority(role, authority)));
            });
            // 人事部员工 ROLE_000023 personalEmployeeRole。无资源

            roleAuthorityRepository.saveAll(roleAuthorityLists);
        }
    }

    /**
     * 超级管理员
     */
    private void initSuperAdmin() {
        Optional<User> sadmin = userRepository.findByAccount(Constant.SUPER_ADMIN_ACCOUNT);
        if (!sadmin.isPresent()) {
            String pwd = passwordEncoder.encode(StringUtils.joinWith("$", "8848@0776", DEFAULT_PASSWORD_SALT));
            // 1、创建超级管理员用户
            superAdminUser = new User("15502916770", Constant.SUPER_ADMIN_ACCOUNT, "张凡斌", pwd, DEFAULT_PASSWORD_SALT, "Frank@aixahc.com", Gender.MALE, null);
            userRepository.save(superAdminUser);
        }
    }

    public void initInternalTenant() {
        Tenant tenant = tenantRepository.findByCode(Constant.INTERNAL_TENANT_CODE);
        if (tenant == null) {
            // 1、创建租户
            internalTenant = new Tenant(Constant.INTERNAL_TENANT_CODE, "系统内置租户", "系统内置租户", "张凡斌", "15502916770", TenantStatus.ENABLE, "http://internal.estate.com", "t_internal", null);
            tenantRepository.save(internalTenant);
            // 2、创建租户超级管理人员信息
            internalTenantEmployee = new TenantEmployee(internalTenant, Constant.tenantAdminCode(internalTenant.getCode()), "张凡斌", "15502916770", Gender.MALE, "Frank@aixahc.com", null);
            tenantEmployeeRepository.save(internalTenantEmployee);
            // 3、创建租户根组织
            internalTenantRootOrg = new Organization(internalTenant, null, null, Constant.tenantRootOrgCode(internalTenant.getCode()), "系统内置租户组织根节点", OrganizationType.ORGANIZATION);
            organizationRepository.save(internalTenantRootOrg);
            // 4、创建租户与根节点组织关联关系
            internalTenant.setRootOrganization(internalTenantRootOrg);
            tenantRepository.save(internalTenant);
            // 5、创建组织、人员、用户关联
            OrganizationEmployee organizationEmployee = new OrganizationEmployee(internalTenantRootOrg, internalTenantEmployee, superAdminUser);
            organizationEmployeeRepository.save(organizationEmployee);
            // 6、创建组织、人员、用户、角色关联
            OrganizationEmployeeRole systemEmployeeRole = new OrganizationEmployeeRole(organizationEmployee, superAdminRole, internalTenant, internalTenantRootOrg, null);
            organizationEmployeeRoleRepository.save(systemEmployeeRole);
        }
    }

    /**
     * 中粮租户管理员
     */
    private void initTenantAdminForZhongliang() {
        Optional<User> sadmin = userRepository.findByAccount(Constant.ZHONGLIANG_ADMIN_ACCOUNT);
        if (!sadmin.isPresent()) {
            String pwd = passwordEncoder.encode(StringUtils.joinWith("$", "8848@9412", DEFAULT_PASSWORD_SALT));
            // 1、创建超级管理员用户
            zhongLiangAdminUser = new User("13289881249", Constant.ZHONGLIANG_ADMIN_ACCOUNT, "李斌", pwd, DEFAULT_PASSWORD_SALT, "libin@aixahc.com", Gender.MALE, null);
            userRepository.save(zhongLiangAdminUser);
        }
    }

    /**
     * 初始化租户数据 <br/>
     * 1、创建sadmin用户 <br/>
     * 2、创建中粮广场租户tenant_zl <br/>
     * 3、创建sadmin的人员信息E_zl000001 <br/>
     * 4、创建根组织ORG_zl000001 <br/>
     * 5、创建租户与根节点组织关联关系 <br/>
     * 6、创建超级管理员角色ROLE_000001 <br/>
     * 7、创建组织、人员、用户关联OrganizationEmployee <br/>
     * 8、创建组织、人员、用户、角色关联OrganizationEmployeeRole <br/>
     */
    private void initZhongLiangTenant() {
        Tenant zhongLiang = tenantRepository.findByCode("tenant_zl");
        if (zhongLiang == null) {
            // 1、创建租户
            Tenant tenant = new Tenant("tenant_zl", "中粮广场", "中粮广场", "李斌", "13289881249", TenantStatus.ENABLE, "http://zhongliang.estate.com", "t_zhongliang", null);
            tenantRepository.save(tenant);
            // 2、创建管理人员信息
            TenantEmployee tenantAdmin = new TenantEmployee(tenant, Constant.tenantAdminCode(tenant.getCode()), "李斌", "13289881249", Gender.MALE, "libin@aixahc.com", null);
            tenantEmployeeRepository.save(tenantAdmin);
            // 3、创建租户根组织
            Organization tenantRootOrg = new Organization(tenant, null, null, Constant.tenantRootOrgCode(tenant.getCode()), "中粮集团总部", OrganizationType.ORGANIZATION);
            organizationRepository.save(tenantRootOrg);
            // 4、创建租户与根节点组织关联关系
            tenant.setRootOrganization(tenantRootOrg);
            tenantRepository.save(tenant);
            // 5、创建组织、人员、用户关联
            OrganizationEmployee organizationEmployee = new OrganizationEmployee(tenantRootOrg, tenantAdmin, zhongLiangAdminUser);
            organizationEmployeeRepository.save(organizationEmployee);
            // 6、创建组织、人员、用户、角色关联
            OrganizationEmployeeRole tenantEmployeeRole = new OrganizationEmployeeRole(organizationEmployee, tenantAdminRole, tenant, tenantRootOrg, null);
            organizationEmployeeRoleRepository.save(tenantEmployeeRole);
        }
    }

}
